package leetcode.N1_N100;

import leetcode.comm.ListNode;

/**
 * @author xiwai [hww282306@alibaba-inc.com]
 * @version 1.0
 * @date 2020/10/13 2:13 下午
 */
public class N83 {

    public static void main(String[] args) {
        ListNode generate = ListNode.generate(1, 1, 2, 3, 3);
        deleteDuplicates(generate);
    }

    public static ListNode deleteDuplicates(ListNode head) {
        ListNode lastNode = head;
        ListNode currentNode = head;
        while (currentNode != null) {
            if (currentNode.val == lastNode.val) {
                lastNode.next = currentNode = currentNode.next;
                continue;
            }
            lastNode = lastNode.next = currentNode;
            currentNode = currentNode.next;
        }
        return head;
    }

}
